package test;

import bean.Emp;
import mapper.EmpMapper;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;

public class App {

    public static void a() throws IOException {
        InputStream in = Resources.getResourceAsStream("config.xml");
        SqlSessionFactory ssf = new SqlSessionFactoryBuilder().build(in);
        SqlSession session = ssf.openSession();
        EmpMapper mapper = session.getMapper(EmpMapper.class);
        Emp emp1 = mapper.findEmpByNo(7967);
        Emp emp2 = mapper.findEmpByNo(7968);
        System.out.println(emp1);
        System.out.println(emp2);
        //mapper.deleteEmp(9999);
        session.clearCache();
        SqlSession session1 = ssf.openSession();
        EmpMapper mapper1 = session.getMapper(EmpMapper.class);
        Emp emp3 = mapper1.findEmpByNo(7967);
        System.out.println(emp3);
    }

    public static void b() throws IOException {
        InputStream in = Resources.getResourceAsStream("config.xml");
        SqlSessionFactory ssf = new SqlSessionFactoryBuilder().build(in);
        SqlSession session1 = ssf.openSession();
        EmpMapper mapper1 = session1.getMapper(EmpMapper.class);
        Emp emp1 = mapper1.findEmpByNo(7960);
        System.out.println(emp1);
        session1.close();
        SqlSession session2 = ssf.openSession();
        EmpMapper mapper2 = session2.getMapper(EmpMapper.class);
        Emp emp2 = mapper2.findEmpByNo(7960);
        System.out.println(emp2);
    }

    public static void main(String[] args) throws IOException {
        b();
    }
}
